
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class PlacementTypeComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public PlacementTypeComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public PlacementType SelectOne(int PlacementTypeId)
        {  
			PlacementManager.DAL.PlacementType_DAL o = new PlacementManager.DAL.PlacementType_DAL();
			o.PlacementTypeId = PlacementTypeId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.PlacementType PlacementTypeToReturn = new PlacementManager.PlacementType((int)row["PlacementTypeId"], (string)row["PlacementTypeName"], (int)row["Year"], (int)row["SemesterId"], (int)row["UnitId"], (int)row["CategoryId"], (int)row["AttendancePatternId"], (int)row["CampusId"], (int)row["RequiredHours"], (DateTime)row["DateStart"], (DateTime)row["DateEnd"], (bool)row["AccruesPoints"], (int)row["NumberOfPoints"], (int)row["PointsRadiusKm"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return PlacementTypeToReturn;
			}
			else
			{
				PlacementManager.PlacementType PlacementTypeToReturnEmpty = new PlacementManager.PlacementType();
                return PlacementTypeToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<PlacementType> SelectAll(string sortExpression)
        {
            List<PlacementType> listPlacementType = new List<PlacementType>();
            PlacementManager.DAL.PlacementType_DAL o = new PlacementManager.DAL.PlacementType_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listPlacementType.Add(new PlacementType((int)row["PlacementTypeId"], (string)row["PlacementTypeName"], (int)row["Year"], (int)row["SemesterId"], (int)row["UnitId"], (int)row["CategoryId"], (int)row["AttendancePatternId"], (int)row["CampusId"], (int)row["RequiredHours"], (DateTime)row["DateStart"], (DateTime)row["DateEnd"], (bool)row["AccruesPoints"], (int)row["NumberOfPoints"], (int)row["PointsRadiusKm"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listPlacementType.Sort(new PlacementTypeComparer(sortExpression));
            return listPlacementType;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<PlacementType> SelectAllWAttendancePatternId(int AttendancePatternId, string sortExpression)
		{
			List<PlacementType> listPlacementType = new List<PlacementType>();
			PlacementManager.DAL.PlacementType_DAL o = new PlacementManager.DAL.PlacementType_DAL();
			o.AttendancePatternId = AttendancePatternId;
			DataSet ds = o.SelectAllWAttendancePatternId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listPlacementType.Add(new PlacementType((int)row["PlacementTypeId"], (string)row["PlacementTypeName"], (int)row["Year"], (int)row["SemesterId"], (int)row["UnitId"], (int)row["CategoryId"], (int)row["AttendancePatternId"], (int)row["CampusId"], (int)row["RequiredHours"], (DateTime)row["DateStart"], (DateTime)row["DateEnd"], (bool)row["AccruesPoints"], (int)row["NumberOfPoints"], (int)row["PointsRadiusKm"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listPlacementType.Sort(new PlacementTypeComparer(sortExpression));
			return listPlacementType;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<PlacementType> SelectAllWCampusId(int CampusId, string sortExpression)
		{
			List<PlacementType> listPlacementType = new List<PlacementType>();
			PlacementManager.DAL.PlacementType_DAL o = new PlacementManager.DAL.PlacementType_DAL();
			o.CampusId = CampusId;
			DataSet ds = o.SelectAllWCampusId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listPlacementType.Add(new PlacementType((int)row["PlacementTypeId"], (string)row["PlacementTypeName"], (int)row["Year"], (int)row["SemesterId"], (int)row["UnitId"], (int)row["CategoryId"], (int)row["AttendancePatternId"], (int)row["CampusId"], (int)row["RequiredHours"], (DateTime)row["DateStart"], (DateTime)row["DateEnd"], (bool)row["AccruesPoints"], (int)row["NumberOfPoints"], (int)row["PointsRadiusKm"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listPlacementType.Sort(new PlacementTypeComparer(sortExpression));
			return listPlacementType;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<PlacementType> SelectAllWCategoryId(int CategoryId, string sortExpression)
		{
			List<PlacementType> listPlacementType = new List<PlacementType>();
			PlacementManager.DAL.PlacementType_DAL o = new PlacementManager.DAL.PlacementType_DAL();
			o.CategoryId = CategoryId;
			DataSet ds = o.SelectAllWCategoryId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listPlacementType.Add(new PlacementType((int)row["PlacementTypeId"], (string)row["PlacementTypeName"], (int)row["Year"], (int)row["SemesterId"], (int)row["UnitId"], (int)row["CategoryId"], (int)row["AttendancePatternId"], (int)row["CampusId"], (int)row["RequiredHours"], (DateTime)row["DateStart"], (DateTime)row["DateEnd"], (bool)row["AccruesPoints"], (int)row["NumberOfPoints"], (int)row["PointsRadiusKm"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listPlacementType.Sort(new PlacementTypeComparer(sortExpression));
			return listPlacementType;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<PlacementType> SelectAllWUnitId(int UnitId, string sortExpression)
		{
			List<PlacementType> listPlacementType = new List<PlacementType>();
			PlacementManager.DAL.PlacementType_DAL o = new PlacementManager.DAL.PlacementType_DAL();
			o.UnitId = UnitId;
			DataSet ds = o.SelectAllWUnitId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listPlacementType.Add(new PlacementType((int)row["PlacementTypeId"], (string)row["PlacementTypeName"], (int)row["Year"], (int)row["SemesterId"], (int)row["UnitId"], (int)row["CategoryId"], (int)row["AttendancePatternId"], (int)row["CampusId"], (int)row["RequiredHours"], (DateTime)row["DateStart"], (DateTime)row["DateEnd"], (bool)row["AccruesPoints"], (int)row["NumberOfPoints"], (int)row["PointsRadiusKm"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listPlacementType.Sort(new PlacementTypeComparer(sortExpression));
			return listPlacementType;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(PlacementType o)
        {	
            PlacementManager.DAL.PlacementType_DAL oPlacementType = new PlacementManager.DAL.PlacementType_DAL();
			oPlacementType.PlacementTypeName = o.PlacementTypeName;
			oPlacementType.Year = o.Year;
			oPlacementType.SemesterId = o.SemesterId;
			oPlacementType.UnitId = o.UnitId;
			oPlacementType.CategoryId = o.CategoryId;
			oPlacementType.AttendancePatternId = o.AttendancePatternId;
			oPlacementType.CampusId = o.CampusId;
			oPlacementType.RequiredHours = o.RequiredHours;
			oPlacementType.DateStart = o.DateStart;
			oPlacementType.DateEnd = o.DateEnd;
			oPlacementType.AccruesPoints = o.AccruesPoints;
			oPlacementType.NumberOfPoints = o.NumberOfPoints;
			oPlacementType.PointsRadiusKm = o.PointsRadiusKm;
			oPlacementType.IsActive = o.IsActive;
			oPlacementType.DateCreated = o.DateCreated;
			oPlacementType.CreatedBy = o.CreatedBy;
			oPlacementType.DateUpdated = o.DateUpdated;
			oPlacementType.UpdatedBy = o.UpdatedBy;

            return oPlacementType.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(string PlacementTypeName, int Year, int SemesterId, int UnitId, int CategoryId, int AttendancePatternId, int CampusId, int RequiredHours, DateTime DateStart, DateTime DateEnd, bool AccruesPoints, int NumberOfPoints, int PointsRadiusKm, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.PlacementType_DAL oPlacementType = new PlacementManager.DAL.PlacementType_DAL();

			oPlacementType.PlacementTypeName = PlacementTypeName;
			oPlacementType.Year = Year;
			oPlacementType.SemesterId = SemesterId;
			oPlacementType.UnitId = UnitId;
			oPlacementType.CategoryId = CategoryId;
			oPlacementType.AttendancePatternId = AttendancePatternId;
			oPlacementType.CampusId = CampusId;
			oPlacementType.RequiredHours = RequiredHours;
			oPlacementType.DateStart = DateStart;
			oPlacementType.DateEnd = DateEnd;
			oPlacementType.AccruesPoints = AccruesPoints;
			oPlacementType.NumberOfPoints = NumberOfPoints;
			oPlacementType.PointsRadiusKm = PointsRadiusKm;
			oPlacementType.IsActive = IsActive;
			oPlacementType.DateCreated = DateCreated;
			oPlacementType.CreatedBy = CreatedBy;
			oPlacementType.DateUpdated = DateUpdated;
			oPlacementType.UpdatedBy = UpdatedBy;

            return oPlacementType.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(PlacementType o)
        {	
            PlacementManager.DAL.PlacementType_DAL oPlacementType = new PlacementManager.DAL.PlacementType_DAL();
			oPlacementType.PlacementTypeId = o.PlacementTypeId;
			oPlacementType.PlacementTypeName = o.PlacementTypeName;
			oPlacementType.Year = o.Year;
			oPlacementType.SemesterId = o.SemesterId;
			oPlacementType.UnitId = o.UnitId;
			oPlacementType.CategoryId = o.CategoryId;
			oPlacementType.AttendancePatternId = o.AttendancePatternId;
			oPlacementType.CampusId = o.CampusId;
			oPlacementType.RequiredHours = o.RequiredHours;
			oPlacementType.DateStart = o.DateStart;
			oPlacementType.DateEnd = o.DateEnd;
			oPlacementType.AccruesPoints = o.AccruesPoints;
			oPlacementType.NumberOfPoints = o.NumberOfPoints;
			oPlacementType.PointsRadiusKm = o.PointsRadiusKm;
			oPlacementType.IsActive = o.IsActive;
			oPlacementType.DateCreated = o.DateCreated;
			oPlacementType.CreatedBy = o.CreatedBy;
			oPlacementType.DateUpdated = o.DateUpdated;
			oPlacementType.UpdatedBy = o.UpdatedBy;

            return oPlacementType.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int PlacementTypeId, string PlacementTypeName, int Year, int SemesterId, int UnitId, int CategoryId, int AttendancePatternId, int CampusId, int RequiredHours, DateTime DateStart, DateTime DateEnd, bool AccruesPoints, int NumberOfPoints, int PointsRadiusKm, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.PlacementType_DAL oPlacementType = new PlacementManager.DAL.PlacementType_DAL();

			oPlacementType.PlacementTypeId = PlacementTypeId;
			oPlacementType.PlacementTypeName = PlacementTypeName;
			oPlacementType.Year = Year;
			oPlacementType.SemesterId = SemesterId;
			oPlacementType.UnitId = UnitId;
			oPlacementType.CategoryId = CategoryId;
			oPlacementType.AttendancePatternId = AttendancePatternId;
			oPlacementType.CampusId = CampusId;
			oPlacementType.RequiredHours = RequiredHours;
			oPlacementType.DateStart = DateStart;
			oPlacementType.DateEnd = DateEnd;
			oPlacementType.AccruesPoints = AccruesPoints;
			oPlacementType.NumberOfPoints = NumberOfPoints;
			oPlacementType.PointsRadiusKm = PointsRadiusKm;
			oPlacementType.IsActive = IsActive;
			oPlacementType.DateCreated = DateCreated;
			oPlacementType.CreatedBy = CreatedBy;
			oPlacementType.DateUpdated = DateUpdated;
			oPlacementType.UpdatedBy = UpdatedBy;

            return oPlacementType.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(PlacementType o)
        {
            PlacementManager.DAL.PlacementType_DAL oPlacementType_DAL = new PlacementManager.DAL.PlacementType_DAL();
            oPlacementType_DAL.PlacementTypeId = o.PlacementTypeId;
            return oPlacementType_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int PlacementTypeId)
        {
            PlacementManager.DAL.PlacementType_DAL oPlacementType_DAL = new PlacementManager.DAL.PlacementType_DAL();
            oPlacementType_DAL.PlacementTypeId = PlacementTypeId;
            return oPlacementType_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWAttendancePatternId(int AttendancePatternId)
		{
			PlacementManager.DAL.PlacementType_DAL oPlacementType_DAL = new PlacementManager.DAL.PlacementType_DAL();
			oPlacementType_DAL.AttendancePatternId = AttendancePatternId;			
			return oPlacementType_DAL.DeleteAllWAttendancePatternId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWCampusId(int CampusId)
		{
			PlacementManager.DAL.PlacementType_DAL oPlacementType_DAL = new PlacementManager.DAL.PlacementType_DAL();
			oPlacementType_DAL.CampusId = CampusId;			
			return oPlacementType_DAL.DeleteAllWCampusId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWCategoryId(int CategoryId)
		{
			PlacementManager.DAL.PlacementType_DAL oPlacementType_DAL = new PlacementManager.DAL.PlacementType_DAL();
			oPlacementType_DAL.CategoryId = CategoryId;			
			return oPlacementType_DAL.DeleteAllWCategoryId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWUnitId(int UnitId)
		{
			PlacementManager.DAL.PlacementType_DAL oPlacementType_DAL = new PlacementManager.DAL.PlacementType_DAL();
			oPlacementType_DAL.UnitId = UnitId;			
			return oPlacementType_DAL.DeleteAllWUnitId();
		}

	}
	
	public class PlacementTypeComparer : IComparer<PlacementType>
    {
        private string _sortColumn;
        private bool _reverse;

        public PlacementTypeComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(PlacementType a, PlacementType b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "PlacementTypeId":
					retVal = String.Compare(a.PlacementTypeId.ToString(), b.PlacementTypeId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "PlacementTypeName":
					retVal = String.Compare(a.PlacementTypeName.ToString(), b.PlacementTypeName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Year":
					retVal = String.Compare(a.Year.ToString(), b.Year.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "SemesterId":
					retVal = String.Compare(a.SemesterId.ToString(), b.SemesterId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UnitId":
					retVal = String.Compare(a.UnitId.ToString(), b.UnitId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CategoryId":
					retVal = String.Compare(a.CategoryId.ToString(), b.CategoryId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AttendancePatternId":
					retVal = String.Compare(a.AttendancePatternId.ToString(), b.AttendancePatternId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CampusId":
					retVal = String.Compare(a.CampusId.ToString(), b.CampusId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "RequiredHours":
					retVal = String.Compare(a.RequiredHours.ToString(), b.RequiredHours.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateStart":
					retVal = String.Compare(a.DateStart.ToString(), b.DateStart.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateEnd":
					retVal = String.Compare(a.DateEnd.ToString(), b.DateEnd.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AccruesPoints":
					retVal = String.Compare(a.AccruesPoints.ToString(), b.AccruesPoints.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "NumberOfPoints":
					retVal = String.Compare(a.NumberOfPoints.ToString(), b.NumberOfPoints.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "PointsRadiusKm":
					retVal = String.Compare(a.PointsRadiusKm.ToString(), b.PointsRadiusKm.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
